<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<c:set scope="request" var="title" value="Message"/>

<sql:setDataSource user="root" password="" driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost/bonix"/>
               <%
                Cookie cookie = null;
                Cookie[] cookies = null;
                // Get an array of Cookies associated with this domain
                cookies = request.getCookies();
                if( cookies != null ){
                   for (int i = 0; i < cookies.length; i++){
                        cookie = cookies[i];
                        if(cookie.getName().equals("username")){
                            %>
<sql:update>
    INSERT INTO messages(sender,receiver,msg,sent_date) VALUES ("<%out.print(""+cookie.getValue()+"");%>",?,?,now())
    <sql:param value="${fn:trim(param.receiver)}"/> 
    <sql:param value="${fn:trim(param.message)}"/>

</sql:update>
                <%
                        }
                   }
                }
                %>
<!DOCTYPE html>
<html>
    <jsp:include page="head.jsp"/>

    <body>
        <jsp:include page="header.jsp"/>

        <div class="row">
            <div class="container">
                <div class="content row">

                    <div class="containerService">

                        <div class="panel-heading">
                            <ul class="navClient navClient-pills">
                                <li><a href='messages.jsp?receiver=gamby'>Message Inbox</a></li>
                                <li class="active"><a href='compose.jsp'>Compose Message</a></li>						
                                <li><a href='sendItems.jsp'>Sent Item</a></li>
                            </ul>
                        </div>

                        <div class="panel-body">
                            <c:redirect url="messages.jsp?receiver=gamby"/>
                        </div><!-- END panel-body -->

                    </div><!-- END containerService -->

                </div><!-- END CONTENT CONTENT ROW -->
            </div><!-- END CONTAINER -->
        </div><!-- END ROW -->

        <jsp:include page="footer.jsp"/>

    </body>
</html>